//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lyq.bean.mySql;

import com.lyq.bean.Course;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

public class SeekElectC_Sql {
    public SeekElectC_Sql() {
    }

    public List<Course> seekElectC_Sql(String sNo, List<Course> list) {
        (new MysqlLinking()).getLink();
        Connection conn = MysqlLinking.conn;
        if (conn != null) {
            try {
                String sql = "SELECT ec.C_No, ec.C_Name, s.S_Name " +
                             "FROM electcourse ec " +
                             "JOIN student s ON ec.S_No = s.S_No " +
                             "WHERE ec.S_No=?";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setString(1, sNo);
                ResultSet rs = ps.executeQuery();

                while(rs.next()) {
                    Course c = new Course();
                    c.setNo(rs.getString("C_No"));
                    c.setName(rs.getString("C_Name"));
                    // 注意：这里只设置了编号和名称，其他字段需要在业务层补充
                    list.add(c);
                }
            } catch (Exception var8) {
                Exception e = var8;
                e.printStackTrace();
            }
        } else {
            System.out.println("数据库连接错误！");
        }

        return list;
    }
    
    /**
     * 查询学生已选课程的完整信息（包括课程类别、学分等）
     * @param sNo 学生学号
     * @param list 用于存放结果的课程列表
     * @return 包含完整信息的课程列表
     */
    public List<Course> seekElectC_SqlWithFullInfo(String sNo, List<Course> list) {
        (new MysqlLinking()).getLink();
        Connection conn = MysqlLinking.conn;
        if (conn != null) {
            try {
                // 使用JOIN查询获取完整的课程信息
                String sql = "SELECT ec.C_No, ec.C_Name, c.C_Time, c.C_Place, c.C_Credit, " +
                             "c.C_Teacher_ID, c.C_LimitNum, c.C_ResidueNum, c.course_type, " +
                             "c.campus, c.category, c.course_classification, s.S_Name " +
                             "FROM electcourse ec " +
                             "JOIN course c ON ec.C_No = c.C_No " +
                             "JOIN student s ON ec.S_No = s.S_No " +
                             "WHERE ec.S_No = ?";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setString(1, sNo);
                ResultSet rs = ps.executeQuery();

                while(rs.next()) {
                    Course c = new Course();
                    c.setNo(rs.getString("C_No"));
                    c.setName(rs.getString("C_Name"));
                    c.setTime(rs.getString("C_Time"));
                    c.setPlace(rs.getString("C_Place"));
                    c.setCredit(rs.getString("C_Credit"));
                    c.setTeacher(rs.getString("C_Teacher_ID"));
                    c.setLimitNum(rs.getString("C_LimitNum"));
                    c.setResidueNum(rs.getString("C_ResidueNum"));
                    c.setCourseType(rs.getString("course_type"));
                    c.setCampus(rs.getString("campus"));
                    c.setCategory(rs.getString("category"));
                    c.setCourseClassification(rs.getString("course_classification"));
                    c.setStudentName(rs.getString("S_Name")); // 添加学生姓名
                    list.add(c);
                }
                
                rs.close();
                ps.close();
            } catch (Exception var8) {
                Exception e = var8;
                e.printStackTrace();
            }
        } else {
            System.out.println("数据库连接错误！");
        }

        return list;
    }
}